#include <iostream>
#include <vector>

using namespace std;

// 100.00 %
class Solution
{
  private:
    vector<vector<int>> res;
    vector<bool> used;

    void generatePermutation(const vector<int> &nums, int index, vector<int> &p)
    {
        if (index == nums.size())
        {
            res.push_back(p);
            return;
        }
        for (int i = 0; i < nums.size(); i++)
        {
            if (!used[i])
            {
                p.push_back(nums[i]);
                used[i] = true;
                generatePermutation(nums, index + 1, p);
                p.pop_back();
                used[i] = false;
            }
        }
        return;
    }

  public:
    vector<vector<int>> permute(vector<int> &nums)
    {
        res.clear();
        if (nums.size() == 0)
            return res;

        used = vector<bool>(nums.size(), false);
        vector<int> p;
        generatePermutation(nums, 0, p);
        return res;
    }
};

int main()
{
    int n = 7;
    vector<int> myVector;
    for (int i = 0; i < n; i++)
    {
        myVector.push_back(i + 1);
    }
    vector<vector<int>> res = Solution().permute(myVector);
    for (int i = 0; i < res.size(); i++)
    {
        for (int j = 0; j < res[i].size(); j++)
        {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}